package com.ceadeal.admin.config;

//import com.mongodb.*;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.mongodb.MongoDbFactory;
//import org.springframework.data.mongodb.core.MongoTemplate;
//import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
//import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
//import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
//import org.springframework.data.mongodb.gridfs.GridFsTemplate;


/**
 * 功能描述: mongodb config
 *
 * 作者: Yzw
 * 日期: 2017-03-01 15:26:50
 */
//@Configuration
public class MongodbConfig {

//    @Value("${custom.data.mongodb.host}")
//    private String host;
//    @Value("${custom.data.mongodb.port}")
//    private Integer port;
//    @Value("${custom.data.mongodb.username}")
//    private String username;
//    @Value("${custom.data.mongodb.password}")
//    private String password;
//    @Value("${custom.data.mongodb.source}")
//    private String source;
//
//    /**
//     * MongoClient
//     */
//    @Bean
//    public MongoClient mongoClient() {
//        // Set credentials
//        MongoCredential credential = MongoCredential.createScramSha1Credential(username, source, password.toCharArray());
//        ServerAddress serverAddress = new ServerAddress(host, port);
//
//        // Set mongoClientOptions
//        MongoClientOptions mongoClientOptions =new MongoClientOptions.Builder()
//                .socketKeepAlive(true)
//                .connectTimeout(10000)
//                .socketTimeout(60000)
//                .readPreference(ReadPreference.primary())
//                .connectionsPerHost(100)
//                .maxWaitTime(120000)
//                .threadsAllowedToBlockForConnectionMultiplier(100)
//                .writeConcern(WriteConcern.NORMAL)
//                .build();
//
//        // Mongo Client
//        MongoClient mongoClient = new MongoClient(serverAddress, Arrays.asList(credential), mongoClientOptions);
//
//        return mongoClient;
//    }
//
//    @Bean
//    public MongoDbFactory mongoDbFactory() throws Exception {
//        // Mongo DB Factory
//        SimpleMongoDbFactory simpleMongoDbFactory = new SimpleMongoDbFactory(mongoClient(), source);
//
//        return simpleMongoDbFactory;
//    }
//
//    @Bean
//    public MongoTemplate mongoTemplate() throws Exception {
//        return new MongoTemplate(mongoDbFactory());
//    }
//
//    @Bean
//    public MongoMappingContext mongoMappingContext() throws Exception {
//        return  new MongoMappingContext();
//    }
//
//    @Bean
//    public MappingMongoConverter mappingMongoConverter() throws Exception {
//        return new MappingMongoConverter(mongoDbFactory(), mongoMappingContext());
//    }
//
//    @Bean
//    public GridFsTemplate gridFsTemplate() throws Exception {
//        return new GridFsTemplate(mongoDbFactory(), mappingMongoConverter());
//    }

}
